//
//  Singleton.m
//  u76ho
//
//  Created by m-air-01 on 16/1/7.
//  Copyright © 2016年 LV. All rights reserved.
//

#import "Singleton.h"
#import "AlertView1.h"
#import "AlertViewTwoBtn.h"
#import "AlertViewOneBtn.h"
#import "AlertBuildAlume.h"
#import "LVCalendarGirdView.h"
#import "AlertViewatuoHidden.h"
static Singleton * single;

@implementation Singleton
UIWindow * RootWindow;

-(void)saveUserInformation
{
    
    //保存用户的code
    if (_code) {
        [NSUserDefaults setObject:_code forKey:@"code"];
    }
    else
    {
        [NSUserDefaults removeObjectForKey:@"code"];
    }
    
    //保存用户的mobile
    if (_mobile) {
        [NSUserDefaults setObject:_mobile forKey:@"mobile"];
    }
    else
    {
        [NSUserDefaults removeObjectForKey:@"mobile"];
    }
    
    //保存用户的密码
    if (_password) {
        [NSUserDefaults setObject:_password forKey:@"password"];
    }
    else
    {
        [NSUserDefaults removeObjectForKey:@"password"];
    }
    
    //推送用的cid
    if (_cid) {
        [NSUserDefaults setObject:_cid forKey:@"cid"];
    }
    else
    {
        [NSUserDefaults removeObjectForKey:@"cid"];
    }
    
    //保存企业的code
    if (_yqcode) {
        [NSUserDefaults setObject:_yqcode forKey:@"yqcode"];
    }
    else
    {
        [NSUserDefaults removeObjectForKey:@"yqcode"];
    }
    
    
    //保存职位名称
    if (_duty) {
        [NSUserDefaults setObject:_duty forKey:@"duty"];
    }
    else
    {
        [NSUserDefaults removeObjectForKey:@"duty"];
    }
    
    
    //保存用户登录信息
    if (_userInformation) {
        [NSUserDefaults setObject:_userInformation forKey:@"userInformation"];
    }
    else
    {
        [NSUserDefaults removeObjectForKey:@"userInformation"];
    }
    
    //保存有效token
    if (_token) {
        [NSUserDefaults setObject:_token forKey:@"token"];
    }
    else
    {
        [NSUserDefaults removeObjectForKey:@"token"];
    }
    
    
    
}
-(void)readUserInformation
{
    
    _duty =[NSUserDefaults objectForKey:@"duty"];
    _code = [NSUserDefaults objectForKey:@"code"];
    _mobile = [NSUserDefaults objectForKey:@"mobile"];
    _yqcode = [NSUserDefaults objectForKey:@"yqcode"];
    _password = [NSUserDefaults objectForKey:@"password"];
    _token = [NSUserDefaults objectForKey:@"token"];
    _userInformation = [NSUserDefaults objectForKey:@"userInformation"];
    
}
+(instancetype)share
{
    @synchronized(self) {
        if (!single) {
            single = [[Singleton alloc]init];
        }
    }
    return single;
}
//普通的弹框
+(void)alerMessage:(NSString *)message img:(NSString *)imageNameStr
{
    AlertView1 * alert = [[AlertView1 alloc]initWithFrame:[UIScreen mainScreen].bounds title:message img:imageNameStr];
    [RootWindow addSubview:alert];
    
    [self performSelector:@selector(hide:) withObject:alert afterDelay:1.0];
    
    
}
+(void)hide:(AlertView1 *)alertView{
    [alertView removeFromSuperviewer];
}
//两个按钮的弹框
+(void)alerTwoBtnMessage:(NSString *)message content:(NSString *)text leftBtnName:(NSString *)leftBtn rightBtnName:(NSString *)rightBtn
{
    AlertViewTwoBtn * alert = [[AlertViewTwoBtn alloc]initWithFrame:[UIScreen mainScreen].bounds title:message content:text leftBtnName:leftBtn rightBtnName:rightBtn];
    [RootWindow addSubview:alert];
}
//一个按钮的弹框
+(void)alerOneBtnMessage:(NSString *)message content:(NSString *)text btnName:(NSString *)btnStr
{
    AlertViewOneBtn * alert = [[AlertViewOneBtn alloc]initWithFrame:[UIScreen mainScreen].bounds title:message content:text btnName:btnStr];
    [RootWindow addSubview:alert];
}
//创建相册的弹框
+(void)alercreateAlumeMessage:(NSString *)message content:(NSString *)text btnName:(NSString *)btnStr
{
    AlertBuildAlume * alert = [[AlertBuildAlume alloc]initWithFrame:[UIScreen mainScreen].bounds title:message content:text btnName:btnStr];
    [RootWindow addSubview:alert];
}
//日历弹框
+(void)alertCalendar
{
    LVCalendarGirdView * alert = [[LVCalendarGirdView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [RootWindow addSubview:alert];
}
//发送消息成功
+(void)alerSendMessage:(NSString *)message
{
    AlertViewatuoHidden * alert = [[AlertViewatuoHidden alloc]initWithFrame:[UIScreen mainScreen].bounds title:message];
    [RootWindow addSubview:alert];
    [self performSelector:@selector(hide2:) withObject:alert afterDelay:1.5];

}
+(void)hide2:(AlertViewatuoHidden *)alert
{
    [alert removeFromSuperviewer];
}
@end
